<?php
require 'vendor/autoload.php';

use QL\QueryList;


$u = 'https://www.meipian.cn/1vncw2pf?share_from=self&v=4.8.2&share_user_mpuuid=6431afe205ed036af998639bb47ca22d&utm_source=singlemessage&from=singlemessage&user_id=8116757&uuid=392e2cc0f8fc58ce8c787f6fec67c37b&utm_medium=meipian_android';
$u = 'https://www.meipian.cn/1vpvjh4n?share_depth=2&user_id=ohbsluPk3GbXJ583_OY7XNcS5004&first_share_uid=8116757&share_user_mpuuid=6431afe205ed036af998639bb47ca22d&v=4.8.2&share_source=singlemessage';
$u = 'https://www.meipian.cn/1vt6444j?share_depth=2&user_id=ohbsluE1kMplaWWkToXwzoEfzyNI&first_share_uid=13450006&share_user_mpuuid=20104bcbda1a1fb85a3b6bb5283be944&v=4.8.1&share_source=timeline';
$u = 'https://www.meipian.cn/1vwh7obn?share_depth=2&user_id=ohbsluE1kMplaWWkToXwzoEfzyNI&first_share_uid=52408943&share_user_mpuuid=f7929a92a3354c82667e58d1a126e20a&v=4.9.0&share_source=singlemessage';
$hj = QueryList::Query($u,array(
    "url"=>array('.content-container','html')
));
$data = $hj->getData(function($x){
    return $x['url'];
});
//print_r($data);


//
//<img show-img="https://ss2.meipian.me/users/8116757/819b4b5baaa3476a9aa15ec7258baf38.jpg?meipian-raw/bucket/ivwen/key/dXNlcnMvODExNjc1Ny84MTliNGI1YmFhYTM0NzZhOWFhMTVlYzcyNThiYWYzOC5qcGc=/sign/d32112dca12d4533888221df59e03832.jpg" src="https://ss2.meipian.me/users/8116757/819b4b5baaa3476a9aa15ec7258baf38.jpg-mobile">

//print_r($data[1]);
preg_match_all('/<img.+src=\"?(.+)\"?.+>/i',$data[0],$match);
//echo $match[1];
//preg_match('/<img show-img="(*)/',$data[1],$matches);
//print_r($match[1]);
//exit;
$newimgs = array();
foreach ($match[1] as $v){
    if(!is_dir('./img')){
        mkdir('./img');
    }
    $filename = put_file_img('./img',$v);
    $newimgs[]=$filename;

}

/* 抓取保存图片函数
     * return
     * $filename  string  图片地址
     */
function put_file_img($dir='',$image='')
{
    // 判断图片的保存类型 截取后四位地址
    $exts = array('jpeg','png','jpg');
    $filename = $dir.'/'.uniqid().time().rand(10000,99999);
   $imgs = explode('.',$image);
    $ext = $imgs[count($imgs)-1];
    $ext = strstr($ext, '-', true);
    $filename = $filename.'.'.$ext;
//   echo $ext;
    $souce = file_get_contents($image);
    if(file_put_contents($filename,$souce)){
        return $filename;
    }else{
        return false;
    }
}

function put_file_img1($dir='',$image='')
{
    // 判断图片的保存类型 截取后四位地址
    $exts = array('jpeg','png','jpg');
    $filename = $dir.'/'.uniqid().time().rand(10000,99999);
    $imgs = explode('.',$image);
    $ext = $imgs[count($imgs)-1];
    $ext = strstr($ext, '?', true);
    $filename = $filename.'.'.$ext;
//   echo $ext;
  $newimg = strstr($image, '?', true);
    $souce = file_get_contents($newimg);
    if(file_put_contents($filename,$souce)){
        return $filename;
    }else{
        return false;
    }
}